package gspringboot

import (
	"gitee.com/hongzhaomin/gspring/annotation"
	"gitee.com/hongzhaomin/gspring/iface"
	"gitee.com/hongzhaomin/hzm-common-go/easylog"
	"io"
	"log/slog"
)

type DefaultLogger struct {
	annotation.Component
	iface.GspringLogger
	log *easylog.EasyLogger
}

func NewDefaultLogger(level slog.Level, filePath string, remote io.Writer) *DefaultLogger {
	return &DefaultLogger{
		log: easylog.NewEasyLogger(level, filePath, remote, 4),
	}
}

// SetLogLevel 设置日志级别 [slog.Level]
func (my *DefaultLogger) SetLogLevel(level slog.Level) {
	my.log.SetLogLevel(level)
}

// Debug logs at [slog.LevelDebug]
func (my *DefaultLogger) Debug(format string, args ...any) {
	my.log.Debug(format, args...)
}

// Info logs at [slog.LevelInfo]
func (my *DefaultLogger) Info(format string, args ...any) {
	my.log.Info(format, args...)
}

// Warn logs at [slog.LevelWarn]
func (my *DefaultLogger) Warn(format string, args ...any) {
	my.log.Warn(format, args...)
}

// Error logs at [slog.LevelError]
func (my *DefaultLogger) Error(format string, args ...any) {
	my.log.Error(format, args...)
}

// Println 直接打印
func (my *DefaultLogger) Println(format string, args ...any) {
	my.log.Println(format, args...)
}

// Close 关闭日志
func (my *DefaultLogger) Close() {
	my.log.Close()
}
